home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / cvs-1.8 / cvs-1 / cvs-1.8.1 / macintosh / server_if.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  1.6 KB  |  68 lines

  1. /*
  2.  * server_if.c
  3.  * Open connection to the CVS server under MacOS
  4.  *
  5.  * Michael Ladwig <mike@twinpeaks.prc.com> --- November 1995
  6.  */
  7.  
  8. #include "cvs.h"
  9.  
  10. #include <GUSI.h>
  11. #include <sys/socket.h>
  12.  
  13. static int read_fd, write_fd;
  14.     
  15. void
  16. macos_start_server (int *tofd, int *fromfd,
  17.           char *client_user,
  18.           char *server_user,
  19.           char *server_host,
  20.           char *server_cvsroot)
  21. {
  22.     char *cvs_server;
  23.     char *command;
  24.     char *portenv;
  25.     struct servent *sptr;
  26.     unsigned short port;
  27.  
  28.     if (! (cvs_server = getenv ("CVS_SERVER")))
  29.         cvs_server = "cvs";
  30.     command = xmalloc (strlen (cvs_server)
  31.                + strlen (server_cvsroot)
  32.                + 50);
  33.     sprintf (command, "%s -d %s server", cvs_server, server_cvsroot);
  34.  
  35.     portenv = getenv("CVS_RCMD_PORT");
  36.     if (portenv)
  37.     port = atoi(portenv);
  38.     else if ((sptr = getservbyname("shell", "tcp")) != NULL)
  39.     port = sptr->s_port;
  40.     else
  41.     error (1, errno, "cannot getservbyname for shell, tcp");
  42.  
  43.     read_fd = rcmd (&server_host,
  44.                     port,
  45.                     client_user,
  46.                 (server_user ? server_user : client_user),
  47.                 command,
  48.                 0);
  49.     if (read_fd < 0)
  50.     error (1, errno, "cannot start server via rcmd");
  51.     
  52.     /* Split the socket into a reading and a writing half.  */
  53.     if ((write_fd = dup (read_fd)) < 0)
  54.         error (1, errno, "duplicating server connection");
  55.     
  56.     *tofd = write_fd;
  57.     *fromfd = read_fd;
  58.     free (command);
  59. }
  60.  
  61.  
  62. void
  63. macos_shutdown_server (int to_server)
  64. {
  65.     if( close (read_fd) != 0 ) perror( "close on read_fd");
  66.     if( close (write_fd) != 0 ) perror( "close on write_fd");
  67. }
  68.